<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admusergroupmouv.php,v $ 
 * $Date: 2005/08/29 15:30:06 $ 
 * $Revision: 1.2 $ 
 * 
 * ********* CVS HEADER ********* 
 */
$i = 0;
if ($mouvgroup != 0) {
	while ($user[$i]) {
		$query = "UPDATE utilisateur SET id_groupe='$mouvgroup' WHERE id='" . $user[$i] . "'";
		$result = rportalrequete($query) or die("ERREUR 0064");
		$query = "DELETE FROM session WHERE id_user='" . $user[$i] . "'";
		$result = rportalrequete($query) or die("ERREUR 0065");
		$i ++;
	}
	$argid = $mouvgroup;
	header("Location: ?op=admusergroupaff&argid=$argid");
} else {
	if ($mouvseq != 0) {
		$groupdefseq = $rportalparams->get_value("RPORTAL","groupe.sequenceur");
		while ($user[$i]) {
			// On recupere les donnees de l'utilisateur $user[$i]
			$query = "SELECT login,id_groupe FROM utilisateur WHERE id='" . $user[$i] . "'";
			$result = rportalrequete($query) or die("ERREUR 0114");
			if ($row = rportalligne($result)) {
				$user_login = $row["login"];
				$user_groupe = $row["id_groupe"];
			}
			//On recupere les donnees sur la sequence a executer
			$query = "SELECT id FROM sequence_ordre WHERE id_sequence='$mouvseq' ORDER BY id";
			$result = rportalrequete($query) or die("ERREUR 0114");
			$etape = -1;
			if ($row = rportalligne($result)) {
				$etape = $row["id"];
			}
			$query = "INSERT INTO sequence_status (login,id_groupe,etape,id_sequence)";
			$query.=" VALUES ('$user_login','$user_groupe','$etape','$mouvseq')";
			$result = rportalrequete($query) or die("ERREUR 0115");
			$query = "DELETE FROM session WHERE id_user='" . $user[$i] . "'";
			$result = rportalrequete($query) or die("ERREUR 0065");
			$query = "UPDATE utilisateur SET id_groupe='$groupdefseq' WHERE id='" . $user[$i] . "'";
			$result = rportalrequete($query) or die("ERREUR 0064");
			$i ++;
		}
		$argid = $groupdefseq;
		header("Location: ?op=admusergroupaff&argid=$argid");
	} else {
		include ("session/erreur404.php");
	}
}
?>